package com.bub.pay.outer.redis;
import com.bub.pay.framework.redis.model.SmsModel;
import com.bub.pay.outer.redis.sms.SmsSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AsyncSmsService implements Runnable {

	/**
	 * Logger
	 */
	private static final Logger log = LoggerFactory.getLogger(AsyncSmsService.class);

	private final SmsModel smsModel;
	private final SmsSender smsSender;

	public AsyncSmsService(final SmsModel smsModel,final SmsSender smsSender) {
		this.smsModel = smsModel;
		this.smsSender = smsSender;
	}

	private boolean isEmptyParam() {
		return null == smsModel || null == smsSender;
	}

	@Override
	public void run() {
		if (isEmptyParam()) {
			log.error("AsyncSmsService parameter must not be null");
			return;
		}
		try {
			smsSender.sendSms(smsModel.getPhoneNum(), smsModel.getTemplateId(), smsModel.getData());
			
		} catch (Exception ex) {
			log.error("AsyncSmsService send email error:", ex);
		}

	}

}
